//
//  UIButton+action.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/3/28.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "UIButton+Action.h"
#import <objc/runtime.h>

static const void *ButtonTargetKey = &ButtonTargetKey;
static const void *ButtonActionKey = &ButtonActionKey;

@implementation UIButton (Action)
#pragma mark - Overried
//-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents{
//    self.target = target;
//    self.actionStr = NSStringFromSelector(action);
//    [super addTarget:target action:action forControlEvents:controlEvents];
//}
//
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    //获取触摸对象
//    UITouch *touche = [touches anyObject];
//    //获取touche的位置
//    CGPoint point = [touche locationInView:self];
//    
//    //判断点是否在button中
//    if (CGRectContainsPoint(self.bounds, point))
//    {
//        //执行action
//        if (self.target != nil&&self.actionStr != nil){
//            [self buttonAction:self];
//            [self.target performSelector:@selector(actionStr) withObject:self];
//        }
//    }
//}

#pragma mark - Event Response
- (void)buttonAction:(UIButton *)btn{
    
}

#pragma mark - Getter
- (id)target{
    return objc_getAssociatedObject(self, ButtonTargetKey);
}

- (NSString *)actionStr{
    return objc_getAssociatedObject(self, ButtonActionKey);
}

#pragma mark - Setter
- (void)setTarget:(id)target{
    objc_setAssociatedObject(self, ButtonTargetKey, target, OBJC_ASSOCIATION_RETAIN);
}

- (void)setActionStr:(NSString *)actionStr{
    objc_setAssociatedObject(self, ButtonActionKey, actionStr, OBJC_ASSOCIATION_RETAIN);
}
@end
